<template>
    <div>
        <Row>
            <Col span="24"
                <Alert show-icon>
                    消费设置
                    <Icon type="ios-bulb-outline" slot="icon"></Icon>
                    <template slot="desc">
                        <alertcontent :content = "content"></alertcontent>
                    </template>
                </Alert>
        </Col>
        </Row>
        <Row>
            <Col span="12">
                <Form :model="consumption" label-position="right" :label-width="150">
                    <FormItem label="市场费率：">
                        <InputNumber :min="0" v-model="consumption.mark_rate"></InputNumber>
                        * 市场费率自定义,每月1号才允许修改
                    </FormItem>
                    <FormItem label="市场手续费：">
                        <InputNumber :min="0" v-model="consumption.mark_sever"></InputNumber>
                    </FormItem>
                    <FormItem label="消费最小金额：">
                        <InputNumber :min="0" v-model="consumption.aiCashMin"></InputNumber>
                        * 最低消费110块
                    </FormItem>
                    <FormItem label="消费最大金额：">
                        <InputNumber :min="0" v-model="consumption.aiCashMax"></InputNumber>
                        * 最高消费20000块
                    </FormItem>
                    <FormItem label="消费开始时间：">
                        <InputNumber :min="0" v-model="consumption.aiCashStime"></InputNumber>
                        * 单位小时，最早开始时间为9
                    </FormItem>
                    <FormItem label="消费结束时间：">
                        <InputNumber :min="0" v-model="consumption.aiCashEtime"></InputNumber>
                        * 单位小时，最晚结束时间为22
                    </FormItem>
                    <FormItem style="text-indent:50px;">
                        <Button @click="savebasesetting" type="primary" :disabled="setAccess">保存</Button>
                    </FormItem>
                </Form>
            </Col>
        </Row>
        <Row>
            <Col span="24"
                <Alert show-icon>
                    支持消费银行 * 每次修改后刷新生效
                    <Icon type="ios-bulb-outline" slot="icon"></Icon>
                    <template slot="desc">
                        
                    </template>
                </Alert>
            </Col>
        </Row>
        <Table :columns="columns" :data="tdata"></Table>
    </div>
</template>
<script>
import alertcontent from '_c/alertcontent/alertcontent'
import { getConfig, setConfig, repaybank } from '@/api/data'
import { getAuthkey, getAccess } from '@/libs/util'
export default {
    name: 'basesetting',
    data() {
        return {
            consumption:{
                mark_rate: 0,
                mark_sever: 0,
                aiCashMin: 0,
                aiCashMax: 0,
                aiCashStime: 0,
                aiCashEtime: 0
            },
            setAccess:true,
            content:[
                '三级四级分润模式还没开启',  '每月1号才允许修改'
            ],
            columns:[
                {
                    title: '银行名',
                    key: 'bank_name'
                },
                {
                    title: '基本费率',
                    key: 'base_rate',
                    render: (h, params) => {
                        return h('div', [
                            h('span',params.row.base_rate + '%')
                        ])
                    }
                },
                {
                    title: '基本手续费',
                    key: 'sever',
                    render: (h, params) => {
                        return h('div', [
                            h('span',params.row.sever + '%')
                        ])
                    }
                },
                {
                    title: '通道类型',
                    key: 'way_type'
                },
                {
                    title: '单笔最大',
                    key: 'pay_limit_deb'
                }
            ],
            tdata:[]
        }
    },
    components: {
        alertcontent
    },
    created() {
        this.setAccess = this.setBtnStatus()
        this.getsetting()
        this.getrepayBank()
    },
    methods: {
        setBtnStatus: function(){
            let access = getAccess()
            if(access.length == 0){
                return true
            } else if (access.indexOf('admin') ==-1) {
                return true
            }else{
                return false
            }
        },
        savebasesetting: function() {
            let data = {
                mark_rate: this.consumption.mark_rate,
                mark_sever: this.consumption.mark_sever,
                aiCashMin: this.consumption.aiCashMin,
                aiCashMax: this.consumption.aiCashMax,
                aiCashStime: this.consumption.aiCashStime,
                aiCashEtime: this.consumption.aiCashEtime
            }
            let reqdata = {
                auth_key: getAuthkey(),
                eidtconfig: JSON.stringify(data)
            }
            setConfig(reqdata).then(res => {
                this.$Message.success('配置保存成功')
                this.getsetting()
            }, err => {
                this.$Message.error(err?err: '保存设置失败')
            })
        },
        getsetting: function() {
            let auth_key = getAuthkey()
            let data = { auth_key  }
            getConfig(data).then(res => {
                if(res.data.code !== 200){
                    this.$Message.error(res.data.error)
                    return
                }
                this.consumption = {
                    mark_rate: parseInt(res.data.data.mark_rate | 0),
                    mark_sever: parseInt(res.data.data.mark_sever | 0),
                    aiCashMin: parseInt(res.data.data.aiCashMin),
                    aiCashMax: parseInt(res.data.data.aiCashMax),
                    aiCashStime: parseInt(res.data.data.aiCashStime | 0),
                    aiCashEtime: parseInt(res.data.data.aiCashEtime | 0)
                }
            }, err => {
                this.$Message.error(err?err: '获取配置信息失败')
            })
        },
        getrepayBank: function(){
            let data = {
                auth_key: getAuthkey()
            }
            repaybank(data).then(res => {
                if(res.data.code !== 200){
                    this.$Message.error(res.data.error)
                    return
                }
                for(let i in res.data.data.data){
                    this.tdata.push(res.data.data.data[i])
                }
            }, err => {
                this.$Message.error(err?err: '获取还款银行错误')
            })
        }
    }
}
</script>
